package com.ruoyi.plugs.blog.entity;



import java.util.Date;


/**
 * token缓存表,用来在各个节点间同步数据
 *
 * @author zb.zhang
 * @date 2017/3/20
 */

//@Entity
public class AccessToken {

    private String appId;//记录所属用户的id
    private String accessToken;//令牌字符串
    private int expiresIn = 7200;//超时时长
    private Date expiresTime;

    private Date createDate;

    public Date getExpiresTime() {
        if (expiresTime == null && getCreateDate() != null) {
            expiresTime = new Date(getCreateDate().getTime() + (expiresIn + 1800) * 1000);
        }
        return expiresTime;
    }

    public boolean isExpired() {
        return getExpiresTime() != null && getExpiresTime().before(new Date());
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public int getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(int expiresIn) {
        this.expiresIn = expiresIn;
    }

    public void setExpiresTime(Date expiresTime) {
        this.expiresTime = expiresTime;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }
}
